﻿using MediatR;
using T.Vehicleservice.Domain.Dtos;
using T.Vehicleservice.Domain.T.Vehicleservice.Model;
using T.Vehicleservice.Read.API.Application.Command.TireUsageRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.Read.API.Application.CommandHandlers.TireUsageRecordCommandHandler
{
    public class TireUsageRecordBackfillCommandHandler : IRequestHandler<TireUsageRecordBackfillCommand, TireUsageRecord>
    {
        private readonly ITireUsageRecordRepository _repository;
        public TireUsageRecordBackfillCommandHandler(ITireUsageRecordRepository repository)
        {
            _repository = repository;
        }
        public async Task<TireUsageRecord> Handle(TireUsageRecordBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _repository.GetAllAsync()).Where(x => x.TireUsageRecordId == request.TireUsageRecordId).FirstOrDefault();
        }
    }
}
